import request from '@/utils/request'

//  获取结算信息----根据购物车
export const findCheckoutInfo = () => {
  return request({url:'/member/order/pre', method:'get'})
} 
//  获取结算信息----根据订单---再次购买
export const findOrderCheckoutInfo = (orderId) => {
  return request({url:'/member/order/repurchase/'+orderId, method:'get'})
} 

//  添加收货地址信息
export const addAddress = (address) => {
  return request({
    url: '/member/address',
    method: 'post',
    data: address
  })
}

//  编辑收货地址信息
export const editAddress = (address) => {
  return request({
    url: `/member/address/${address.id}`,
    method: 'put',
    data: address
  })
}

// 提交订单
export const createOrder = (order) => {
  return request({
    url: '/member/order',
    method: 'post',
    data: order
  })
}

// 获取订单详情
export const findOrder = (id) => {
  return request({
    url: '/member/order/'+ id ,
    method: 'get'
  })
}

// 查询订单列表
export const findOrderList = ( params ) => {
  return request({
    url: '/member/order',
    method: 'get',
    params
  })
}

// 取消订单
export const cancelOrder = ( { orderId, cancelReason } ) => {
  return request({
    url: `/member/order/${orderId}/cancel`,
    method: 'put',
    data:{ cancelReason }
  })
}

// 删除订单
export const deleteOrder = (orderId ) => {
  return request({
    url: `/member/order`,
    method: 'delete',
    data:{ ids: [orderId] }
  })
}
// 模拟发货
export const simulateDelivery = (orderId) => {
  return request({
    url: `/member/order/consignment/${orderId}`,
    method: 'get'
  })
}

// 确认收货
export const confirmOrder = (orderId) => {
  return request({
    url: `/member/order/${orderId}/receipt`,
    method: 'put'
  })
}


// 查询物流
export const selectLogistics = (orderId) => {
  return request({
    url: `/member/order/${orderId}/logistics`,
    method: 'GET'
  })
}